;
(function($) {
	$(document).ready(function() {
		//添加用户名
		function ifUserEmail(){
			if(getCookie('userEmail')) {
				$('.user-login').css({
					display: 'none'
				})
				$('#user-information').css({
					display: 'block'
				})
				$('.user-name').html(getCookie('userEmail'))
			}
		}
		ifUserEmail()
		//监听滚轮到达底部自动加载更多

		/*//console.log($(document).scrollTop())
		if($(document).scrollTop() - $(document).height() + $(window).height() >= -20) {
			//距离底部20

			data.pagenum++;
			console.log(data)
			moreGoods(data);
			var scrollX = $(document).scrollTop();
			$(document).scrollTop(scrollX - 160)
		}*/
		$(document).scroll(function() {
			//console.log($(document).scrollTop())
			//回到顶部
			$('#goTop').click(function() {
				$(document).scrollTop(0);
			})

			//头部滚动定位
			if(0 < $(document).scrollTop() < 1.9) {
				//console.log('aaaaa')
				$('#scoll-top').stop().animate({
					top: -46
				}, 300)
			}
			if($(document).scrollTop() == 0) {
				//console.log('bbbb')
				$('#scoll-top').stop().animate({
					top: 0
				}, 300)
			}

		})
		
		/*登出按钮*/
		$('#log-out').click(function(){
			removeCookie('userEmail');
			ifUserEmail()
		})
		
		
		
		
		
		//二级导航滑过效果。。。。。。。。。
		//二级导航滑过效果
		let olis = document.querySelectorAll('.second-nav-l a');
		let oimgs = document.querySelectorAll('.second-nav-r-img img');
		// console.log(olis)
		// console.log(oimgs)
		let wrapperSecondNav=document.querySelector('.wrapper-second-nav')
		let secondNavR=document.querySelector('.second-nav-r');
		let container=document.querySelector('.container');
		let mainNav=document.querySelector('.main-nav')
		function html(arr, arr2) {

			wrapperSecondNav.style.display = 'block';
			secondNavR.style.display = 'block';
			for(let i = 0; i < olis.length; i++) {
				olis[i].innerHTML = '';
				if(arr[i]) {
					olis[i].innerHTML = arr[i];
				}
			}
			for(let j = 0; j < oimgs.length; j++) {
				oimgs[j].src = null;
				if(arr2[j]) {
					oimgs[j].src = arr2[j]
				}
			}
		}

		container.onmouseenter = function(e) {
			//console.log(e.target);
			container.onmousemove = function(evt) {
				if(evt.target.className == 'open-second-nav second-nav-1') {
					html(secondWord1, secondImg1)
				} else if(evt.target.className == 'open-second-nav second-nav-2') {
					html(secondWord2, secondImg2)
				} else if(evt.target.className == 'open-second-nav second-nav-3') {
					html(secondWord3, secondImg3)
				} else if(evt.target.className == 'open-second-nav second-nav-4') {
					html(secondWord4, secondImg1)
				} else if(evt.target.className == 'open-second-nav second-nav-5') {
					html(secondWord5, secondImg4)
				} else if(evt.target.className == 'open-second-nav second-nav-6') {
					html(secondWord6, secondImg2)
					secondNavR.style.display = 'none'
				}else if(evt.target.className == 'nav-special'){
					wrapperSecondNav.style.display = 'none';
				}

			}
			container.onmouseleave = function(eve) {
				//console.log('离开2级标题22222');
				mainNav.onmousemove = null;
				wrapperSecondNav.style.display = 'none';
				eve.stopPropagation();
			}
			//鼠标滑过图片效果
			//			$('.addImg').onmousemove=function(evt){
			//				console.log(evt.target)
			//			}

		}
		
		
		
		
		//点击2级标题跳转
		$('.second-nav a').click(function(){
			//console.log(1)
			this.href=`second-list.html`
		})

	})
})(jQuery);

		//点击购物车跳转
		$('.mini-cart').click(()=>location.href=`shopping-cart.html`)
		
		
		
		//myNum开始	
		//查询用户购物车商品
		//http://jx.xuzhixiang.top/ap/api/cart-list.php?id=1
		function myNum(){
			var selectCarAPI=`http://jx.xuzhixiang.top/ap/api/cart-list.php?id=${getCookie('uid')}`
			$.ajax({
				url:selectCarAPI,
				type:'get',
				success:function(selectCarContent){
					
					var arrSelectCar=JSON.parse(selectCarContent).data;
					//console.log(arrSelectCar)
					var pNum=0;
					arrSelectCar.forEach(function(product){
						pNum += Number(product.pnum);
					})
								
					$('.cart-num').html(pNum)
				}
			})



		}
		myNum();
		//myNum结束	